package com.jackaltsc.mydemolist.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

import com.jackaltsc.mydemolist.R;
import com.jackaltsc.mydemolist.adapter.StuListAdapter;
import com.jackaltsc.mydemolist.entity.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * 稍微复杂一点的ListView 结合自己实现的BaseAdapter来完成
 * Created by JackalTsc on 2016/7/13.
 */
public class ListView2Activity extends Activity {

    private ListView mListView;

    //ListView的适配器
    private StuListAdapter mStuAdapter;

    //学生列表的数据
    private List<Student> mData = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_activity_listcom);

        initListView();
    }

    private void initListView() {

        //模拟获取数据
        getStuData();

        mListView = (ListView) findViewById(R.id.lv_students);
        //初始化适配器Adapter
        mStuAdapter = new StuListAdapter(this, mData);
        mListView.setAdapter(mStuAdapter);
    }

    private void getStuData() {
        for (int i = 0; i < 20; i++) {
            mData.add(new Student(R.mipmap.ic_launcher, "王小明" + i));
        }
    }
}
